package org.Console;

import static org.junit.Assert.*;

import org.junit.Test;

import pasantias.Dominio.BoardBuilder;
import pasantias.Dominio.Circle;
import pasantias.Dominio.Dot;
import pasantias.Dominio.InmutableBoard;
import pasantias.Dominio.Rectangle;
import pasantias.Dominio.Square;


public class testConsole{

	@Test
	public void smallBoard(){
		
		InmutableBoard inmutableBoard = new BoardBuilder(2, 2).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("----", text.toString(0));
		assertEquals("|  |", text.toString(1));
		assertEquals("|  |", text.toString(2));
		assertEquals("----", text.toString(3));
	}
	
	@Test
	public void insertSquare(){
		
		Dot dot = new Dot(2,2);
		InmutableBoard inmutableBoard = new BoardBuilder(4, 4).addFigure(new Square(dot, 2)).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("------", text.toString(0));
		assertEquals("|    |", text.toString(1));
		assertEquals("| ** |", text.toString(2));
		assertEquals("| ** |", text.toString(3));
		assertEquals("|    |", text.toString(4));
		assertEquals("------", text.toString(5));
	}
	
	@Test
	public void insertBigSquare() throws Exception{
		
		Dot dot = new Dot(2,2);
		InmutableBoard inmutableBoard = new BoardBuilder(6, 6).addFigure(new Square(dot, 4)).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("--------", text.toString(0));
		assertEquals("|      |", text.toString(1));
		assertEquals("| **** |", text.toString(2));
		assertEquals("| **** |", text.toString(3));
		assertEquals("| **** |", text.toString(4));
		assertEquals("| **** |", text.toString(5));
		assertEquals("|      |", text.toString(6));
		assertEquals("--------", text.toString(7));
	}
	
	@Test
	public void insertRectangle() throws Exception{
		Dot dot = new Dot(2,2);
		InmutableBoard inmutableBoard = new BoardBuilder(6, 6).addFigure(new Rectangle(dot, 2, 4)).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);

		assertEquals("--------", text.toString(0));
		assertEquals("|      |", text.toString(1));
		assertEquals("| **   |", text.toString(2));
		assertEquals("| **   |", text.toString(3));
		assertEquals("| **   |", text.toString(4));
		assertEquals("| **   |", text.toString(5));
		assertEquals("|      |", text.toString(6));
		assertEquals("--------", text.toString(7));
	}
	
	@Test
	public void insertBigRectangle() throws Exception{
		
		Dot dot = new Dot(6,2);
		InmutableBoard inmutableBoard = new BoardBuilder(10, 10).addFigure(new Rectangle(dot, 2, 4)).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("------------", text.toString(0));
		assertEquals("|          |", text.toString(1));
		assertEquals("|     **   |", text.toString(2));
		assertEquals("|     **   |", text.toString(3));
		assertEquals("|     **   |", text.toString(4));
		assertEquals("|     **   |", text.toString(5));
		assertEquals("|          |", text.toString(6));
		assertEquals("|          |", text.toString(7));
		assertEquals("|          |", text.toString(8));
		assertEquals("|          |", text.toString(9));
		assertEquals("|          |", text.toString(10));
		assertEquals("------------", text.toString(11));
	}
	
	@Test
	public void insertRectangleFailed() throws Exception{
		
		Dot dot = new Dot(5,2);
		Text text = new Text();
		
		try{
			InmutableBoard inmutableBoard = new BoardBuilder(10, 10).addFigure(new Rectangle(dot, 8, 4)).build();
			text.draw(inmutableBoard);
			fail("This rectangle shouldn't be created");
		}catch(RuntimeException exception){
			assertEquals("The rectangle does not fit in the Board!!",exception.getMessage());
		}
		
	}
	
	@Test
	public void insertCircle(){
		
		Dot centre = new Dot(3,3);
		InmutableBoard inmutableBoard = new BoardBuilder(5, 6).addFigure(new Circle(centre,1)).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("-------", text.toString(0));
		assertEquals("|     |", text.toString(1));
		assertEquals("|  *  |", text.toString(2));
		assertEquals("| *** |", text.toString(3));
		assertEquals("|  *  |", text.toString(4));
		assertEquals("|     |", text.toString(5));
		assertEquals("|     |", text.toString(6));
		assertEquals("-------", text.toString(7));
	}
	
	@Test
	public void insertCircleFailed() throws Exception{
		
		Dot centre = new Dot(3,2);		
		Text text = new Text();
				
		try{
			InmutableBoard inmutableBoard = new BoardBuilder(5, 7).addFigure(new Circle(centre,3)).build();
			text.draw(inmutableBoard);
			fail("This circle shouldn't be created");
		}catch(RuntimeException exception){
			assertEquals("The circle does not fit in the Board!!",exception.getMessage());
		}
	}

	@Test
	public void insertBigCircle(){
		
		Dot centre = new Dot(8,6);
		InmutableBoard inmutableBoard = new BoardBuilder(20, 20).addFigure(new Circle(centre,5)).build();
		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("----------------------", text.toString(0));
		assertEquals("|                    |", text.toString(1));
		assertEquals("|                    |", text.toString(2));
		assertEquals("|                    |", text.toString(3));
		assertEquals("|    *******         |", text.toString(4));
		assertEquals("|   *********        |", text.toString(5));
		assertEquals("|  ***********       |", text.toString(6));
		assertEquals("|   *********        |", text.toString(7));
		assertEquals("|    *******         |", text.toString(8));
		assertEquals("|                    |", text.toString(9));
		assertEquals("|                    |", text.toString(10));
		assertEquals("|                    |", text.toString(11));
		assertEquals("|                    |", text.toString(12));
		assertEquals("|                    |", text.toString(13));
		assertEquals("|                    |", text.toString(14));
		assertEquals("|                    |", text.toString(15));
		assertEquals("|                    |", text.toString(16));
		assertEquals("|                    |", text.toString(17));
		assertEquals("|                    |", text.toString(18));
		assertEquals("|                    |", text.toString(19));
		assertEquals("|                    |", text.toString(20));
		assertEquals("----------------------", text.toString(21));
	}
	
	@Test
	public void insertDot() throws Exception{
		
		InmutableBoard inmutableBoard = new BoardBuilder(5, 6).addFigure(new Dot(3,3)).build();		
		Text text = new Text();
		text.draw(inmutableBoard);
		
		assertEquals("-------", text.toString(0));
		assertEquals("|     |", text.toString(1));
		assertEquals("|     |", text.toString(2));
		assertEquals("|  *  |", text.toString(3));
		assertEquals("|     |", text.toString(4));
		assertEquals("|     |", text.toString(5));
		assertEquals("|     |", text.toString(6));
		assertEquals("-------", text.toString(7));
	}
	
}
